package com.example.administrator.pms.bean;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;


public class MySQLiteHelper extends SQLiteOpenHelper {

    private static final String DBNAME = "picture.db";
    private static final int VERSION = 3;
    private static final String TBL_PICTURE = "picture";//创建名为picture的表
    private static final String TBL_PICTURE_COLUMN_URL = "_url";
    private static final String TBL_PICTURE_COLUMN_NAME = "_name";
    private static final String TBL_PICTURE_COLUMN_LABEL = "_label";

    private static final String TBL_PICTURE_COLUMN_PICID = "_picid";

    public MySQLiteHelper(Context context) {
        super(context, DBNAME, null, VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        //创建一个数据库以及表格
        StringBuffer sb = new StringBuffer();
        sb.append("create table if not exists ");
        sb.append(TBL_PICTURE + " (");
        sb.append(TBL_PICTURE_COLUMN_PICID + " INTEGER PRIMARY KEY, ");
        sb.append(TBL_PICTURE_COLUMN_URL + " varchar(100), ");
        sb.append(TBL_PICTURE_COLUMN_NAME + " varchar(100), ");
        sb.append(TBL_PICTURE_COLUMN_LABEL + " varchar(100)");
        sb.append(")");
        db.execSQL(sb.toString());
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        //数据库更新
        String newSql = "drop table if exists " + TBL_PICTURE;
        db.execSQL(newSql);
        onCreate(db);
    }
}
